#include <sstream>
#include <vector>

namespace {
	struct Point {
		double x;
		double y;
	};
	struct Branch {
		size_t leftVert;
		size_t rightVert;
		std::vector<Point> points;
	};
	std::vector<std::vector<Branch>> neurons
	{
		{
			{0, 1,
				{
					{0.0, 0.0},
					{1.0, 0.0},
					{3.0, 0.0},
					{4.0, 0.0},
					{7.0, 0.0},
				}
			},
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{3.0, 0.0},
					{4.0, 0.0},
					{6.0, 0.0},
					{7.0, 0.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{1.0, 0.0},
					{3.0, 0.0},
					{4.0, 0.0},
					{7.0, 0.0},
				},
			}
		}, {
			{0, 1,
				{
					{0.0, 1.0},
					{3.0, 1.0},
					{4.0, 1.0},
					{6.0, 1.0},
					{7.0, 1.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{1.0, 0.0},
					{3.0, 0.0},
					{4.0, 0.0},
					{7.0, 0.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.5},
					{1.0, 1.5},
					{2.0, 0.5},
					{3.0, 1.5},
					{4.0, 0.5},
					{5.0, 1.5},
					{6.0, 0.5},
					{7.0, 1.5},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.5},
					{1.0, 1.5},
					{2.0, 0.5},
					{3.0, 1.5},
					{4.0, 0.5},
					{5.0, 1.5},
					{6.0, 0.5},
					{7.0, 1.5},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.5},
					{1.0, -.5},
					{2.0, 0.5},
					{3.0, -.5},
					{4.0, 0.5},
					{5.0, -.5},
					{6.0, 0.5},
					{7.0, -.5},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, -.5},
					{1.0, 0.5},
					{2.0, -.5},
					{3.0, 0.5},
					{4.0, -.5},
					{5.0, 0.5},
					{6.0, -.5},
					{7.0, 0.5},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.5},
					{1.0, 1.5},
					{2.0, 0.5},
					{3.0, 1.5},
					{4.0, 0.5},
					{5.0, 1.5},
					{6.0, 0.5},
					{7.0, 1.5},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{1.0, 0.0},
					{3.0, 0.0},
					{4.0, 0.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 1.0},
					{3.0, 1.0},
					{4.0, 1.0},
					{6.0, 1.0},
					{7.0, 1.0},
					{8.0, 1.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{1.0, 0.0},
					{3.0, 0.0},
					{4.0, 0.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 1.0},
					{3.0, 1.0},
					{4.0, 1.0},
					{6.0, 1.0},
					{6.0, 0.0},
					{7.0, 0.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{1.0, 0.0},
					{3.0, 0.0},
				}
			}, {1, 2,
				{
					{3.0, 0.0},
					{4.0, 1.0},
					{6.0, 3.0},
				}
			}, {1, 3,
				{
					{3.0, 0.0},
					{4.0, 0.0},
				}
			}, {3, 4,
				{
					{4.0, 0.0},
					{7.0, 0.0},
					{8.0, 0.0},
					{10.0, 0.0},
				}
			}, {3, 5,
				{
					{4.0, 0.0},
					{7.0, -3.0},
					{8.0, -4.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{2.0, 0.0},
					{3.0, 0.0},
				}
			}, {1, 2,
				{
					{3.0, 0.0},
					{4.0, -1.0},
					{5.0, -2.0},
					{7.0, -4.0},
				}
			}, {1, 3,
				{
					{3.0, 0.0},
					{4.0, 0.0},
				}
			}, {3, 4,
				{
					{4.0, 0.0},
					{7.0, 0.0},
					{8.0, 0.0},
					{10.0, 0.0},
				},
			}, {3, 5,
				{
					{4.0, 0.0},
					{6.0, 2.0},
					{7.0, 3.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{2.0, 0.0},
					{3.0, 0.0},
				}
			}, {1, 2,
				{
					{3.0, 0.0},
					{4.0, 1.0},
					{5.0, 2.0},
					{6.0, 3.0},
				}
			}, {1, 3,
				{
					{3.0, 0.0},
					{5.0, 0.0},
					{6.0, 0.0},
					{9.0, 0.0},
					{10.0, 0.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{2.0, 0.0},
					{4.0, 0.0},
				}
			}, {1, 2,
				{
					{4.0, 0.0},
					{7.0, 0.0},
					{8.0, 0.0},
					{10.0, 0.0},
				}
			}, {1, 3,
				{
					{4.0, 0.0},
					{6.0, 2.0},
					{7.0, 3.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{2.0, 0.0},
					{3.0, 0.0},
				}
			}, {1, 2,
				{
					{3.0, 0.0},
					{4.0, 1.0},
					{6.0, 3.0},
				}
			}, {1, 3,
				{
					{3.0, 0.0},
					{5.0, 0.0},
					{6.0, 0.0},
					{9.0, 0.0},
					{10.0, 0.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{2.0, 0.0},
					{4.0, 0.0},
					{7.0, 0.0},
					{8.0, 0.0},
					{10.0, 0.0},
				}
			}
		}, {
			{0, 1,
				{
					{-2.0, -1.0},
					{-0.0, 1.0},
					{2.0, -1.0},
				}
			}
		}, {
			{0, 1,
				{
					{-2.0, -1.5},
					{-0.0, -1.0},
					{2.0, -1.5},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{6.0, 0.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.5},
					{2.0, 0.5},
					{3.0, 2.0},
					{4.0, 0.5},
					{6.0, 0.5},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{6.0, 0.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.5},
					{2.0, 0.5},
					{3.0, 2.0},
					{6.0, 2.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{4.0, 0.0},
					{6.0, 4.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.5},
					{2.0, 0.5},
					{3.0, 2.0},
					{4.5, 5.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{2.0, 0.0},
					{3.0, 0.0},
				}
			},
			{1, 2,
				{
					{3.0, 0.0},
					{4.0, 0.0},
					{6.0, 0.0},
				}
			},
			{1, 3,
				{
					{3.0, 0.0},
					{4.0, 1.0},
					{5.0, 2.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{1.0, 0.0},
				}
			},
			{1, 2,
				{
					{1.0, 0.0},
					{3.0, 0.0},
					{6.0, 0.0},
				}
			},
			{1, 3,
				{
					{1.0, 0.0},
					{2.0, 1.0},
					{3.0, 2.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{2.0, 0.0},
					{3.0, 0.0},
				}
			},
			{1, 2,
				{
					{3.0, 0.0},
					{4.0, 0.0},
					{6.0, 0.0},
				}
			},
			{1, 3,
				{
					{3.0, 0.0},
					{4.0, 1.0},
					{5.0, 2.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{1.0, 0.0},
					{2.0, 0.0},
				}
			},
			{1, 2,
				{
					{2.0, 0.0},
					{3.0, 0.0},
					{6.0, 0.0},
				}
			},
			{1, 3,
				{
					{2.0, 0.0},
					{3.0, 1.0},
					{4.0, 2.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{1.0, 0.0},
					{2.0, 0.0},
				}
			},
			{1, 2,
				{
					{2.0, 0.0},
					{3.0, 0.0},
					{6.0, 0.0},
				}
			},
			{1, 3,
				{
					{2.0, 0.0},
					{3.0, 1.0},
					{4.0, 2.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{1.0, 0.0},
					{2.0, 0.0},
				}
			},
			{1, 2,
				{
					{2.0, 0.0},
					{3.0, 0.0},
					{6.0, 0.0},
				}
			},
			{1, 3,
				{
					{2.0, 0.0},
					{3.0, 1.0},
					{4.0, 2.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{2.0, 0.0},
					{3.0, 0.0},
					{4.0, 0.0},
					{6.0, 0.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{2.0, 0.0},
					{3.0, 0.0},
					{3.0, 1.0},
					{3.0, 3.0},
				}
			}
		}, {
			{0, 1,
				{
					{0.0, 0.0},
					{1.5, 0.2},
					{2.0, 0.1},
					{3.2, 0.2},
					{4.0, -0.1}
				}
			},
			{1, 2,
				{
					{4.0, -0.1},
					{5.0, 1.0},
					{6.5, 2.6},
					{8.0, 4.2},
					{8.6, 5.2},
				}
			},
			{1, 3,
				{
					{4.0, -0.1},
					{4.5, 0.1},
					{6.5, 0.2},
					{7.5, 0.0},
					{8.5, 0.1},
					{10.0, 0.1},
				}
			}
		}, {
			{0, 1,
				{
					{0.1, -0.1},
					{0.7, 0.0},
					{1.7, 0.2},
					{2.0, 0.1},
					{2.9, 0.2},
					{3.8, 0.1},
				}
			},
			{1, 2,
				{
				{3.8, 0.1},
				{4.5, 0.8},
				{5.5, 1.9},
				{7.0, 3.4},
				{7.9, 4.4},
				{8.7, 5.6},
				}
			},
			{1, 3,
				{
				{3.8, 0.1},
				{4.9, 0.0},
				{5.4, -0.1},
				}
			},
			{3, 4,
				{
				{5.4, -0.1},
				{6.2, -.8},
				{7.5, -1.9},
				{8.6, -3.2},
				}
			},
			{3, 5,
				{
				{5.4, -0.1},
				{6.9, -0.0},
				{7.9, -0.2},
				{8.3, -0.1},
				{9.6, -0.0},
				}
			}
		}
	};
}
std::string getTestData() {
	std::ostringstream oss{};
	size_t npoints=0;
	size_t nbr=0;
	for(auto& n: neurons) {
		npoints+=n.size()+1;
		nbr+=n.size();
	}
	oss<<npoints<<"\n";
	for(size_t i=0; i<npoints; i++)
		oss<<"1\n";
	size_t k=0;
	oss<<nbr<<"\n";
	for(auto& n: neurons) {
		for(auto& b: n) {
			oss<<"0 "<<b.leftVert+k<<" "<<b.rightVert+k<<" "<<b.points.size()<<"\n";
			for(auto& p: b.points) {
				oss<<"0 "<<int(p.x*256)<<" ";
				oss<<int(p.y*256)<<" ";
				oss<<"0 256\n";
			}
		}
		k+=n.size()+1;
	}
	oss<<neurons.size()<<"\n";
	k=0;
	size_t l=1;
	for(auto& n: neurons) {
		oss<<k<<" Neuron "<<l<<"\n";
		k+=n.size()+1;
		l++;
	}
	return oss.str();
}

